package org.twnmayberry.dto;

import java.util.ArrayList;
import java.util.List;

import org.twnmayberry.bo.Activity;
import org.twnmayberry.bo.POI;

public class DTOUtils {

	
	public static POI convertDTOtoPOI(POIDTO newPOI) {
		POI newPeep = new POI();
		
		if(newPOI.getId() != 0) {
			newPeep.setId(newPOI.getId());
		}
		List<Activity> newActs = new ArrayList<Activity>();
		
		for(ActivityDTO act : newPOI.getActivities()) {
			newActs.add(convertDTOtoActivity(act));
		}
		newPeep.setActivities(newActs);
		
		newPeep.setFirstName(newPOI.getFirstName());
		newPeep.setMiddleName(newPOI.getMiddleName());
		newPeep.setLastName(newPOI.getLastName());
		newPeep.setGender(newPOI.getGender());
		newPeep.setHeight(newPOI.getHeight());
		newPeep.setWeight(newPOI.getWeight());
		
		return newPeep;
	}
	
	public static Activity convertDTOtoActivity(ActivityDTO newAct) {
		Activity newActivity = new Activity();
		
		if(newAct.getId() != 0) {
			newActivity.setId(newAct.getId());
		}
		newActivity.setDate(newAct.getDate());
		newActivity.setDescription(newAct.getDescription());
		newActivity.setType(newAct.getType());
		
		return newActivity;
	}
	
	public static POIDTO convertPOItoDTO(POI newPOI) {
		POIDTO newPeep = new POIDTO();
		
		newPeep.setId(newPOI.getId());
		List<ActivityDTO> newActs = new ArrayList<ActivityDTO>();
		
		for(Activity act : newPOI.getActivities()) {
			newActs.add(convertActivitytoDTO(act));
		}
		newPeep.setActivities(newActs);
		
		newPeep.setFirstName(newPOI.getFirstName());
		newPeep.setMiddleName(newPOI.getMiddleName());
		newPeep.setLastName(newPOI.getLastName());
		newPeep.setGender(newPOI.getGender());
		newPeep.setHeight(newPOI.getHeight());
		newPeep.setWeight(newPOI.getWeight());
		
		return newPeep;
	}
	
	public static ActivityDTO convertActivitytoDTO(Activity newAct) {
		ActivityDTO newActivity = new ActivityDTO();
		newActivity.setId(newAct.getId());
		newActivity.setDate(newAct.getDate());
		newActivity.setDescription(newAct.getDescription());
		newActivity.setType(newAct.getType());
		
		return newActivity;
	}
}
